/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

typedef struct {
  %immutable;
  int dim;
  int size_struct;
  int link_overlap;  
  int link_position;
  int link_number; 
  int bps;                  
  int spp;                  
  int ref3d;                 
  FLGR_Type type;           
  FLGR_Shape shape;         
  FLGR_Connexity connexity; 
  int size_y;               
  int size_x;               
  FLGR_Data1D **row;       
  void **array; 
  %mutable;
}FLGR_Data2D;


%extend FLGR_Data2D {
  FLGR_Data2D(int size_y, int size_x, int spp, FLGR_Type type) {
    return flgr2d_create_pixmap(size_y, size_x, spp, type);
  }

  FLGR_Data2D(int size_y, int size_x, int spp, FLGR_Type type, FLGR_Shape shape, FLGR_Connexity connexity) {
    return flgr2d_create_neighborhood(size_y, size_x, spp,type, shape, connexity);
  }

  FLGR_Data2D(int spp, FLGR_Type type, FLGR_Connexity connexity) {
    return flgr2d_create_neighborhood_from_connexity(spp,type, connexity);
  }

  FLGR_Data2D(FLGR_Data2D *dat) {
    if(dat->shape == FLGR_NO_SHAPE) {
      return flgr2d_create_from(dat);
    }else {
      return flgr2d_create_neighborhood_from(dat);
    }
  }

  FLGR_Data2D(char *filename) {
    int len = strlen(filename);

 
    if((len>=4) && (strcmp(filename+len-4,".png")==0))
      return flgr2d_load_png(filename);

    else if((len>=4) && (strcmp(filename+len-4,".bmp")==0))
      return flgr2d_load_bmp(filename);

    else if((len>=4) && (strcmp(filename+len-4,".tif")==0))
      return flgr2d_load_tiff(filename);

    else if((len>=5) && (strcmp(filename+len-5,".tiff")==0))
      return flgr2d_load_tiff(filename);

    else if((len>=4) && (strcmp(filename+len-4,".pgm")==0))
      return flgr2d_load_pgm(filename);

    else if((len>=4) && (strcmp(filename+len-4,".jpg")==0))
      return flgr2d_load_jpeg(filename);

    else if((len>=5) && (strcmp(filename+len-5,".jpeg")==0))
      return flgr2d_load_jpeg(filename);

    else 
      return NULL;

  }

  ~FLGR_Data2D() {
    if($self->link_overlap == -1) {
      flgr2d_destroy($self);
    }else {
      flgr2d_destroy_link($self);
    }
  }

  FLGR_Data2D* create_link(int partsNumber, int partIndex, int overlapSize) {
    return flgr2d_create_pixmap_link($self, partsNumber, partIndex, overlapSize);
  }

  int __lt__(FLGR_Data2D *dat) {
    return (flgr2d_compare($self, "<", dat)==FLGR_TRUE);
  }
  int __le__(FLGR_Data2D *dat) {
    return (flgr2d_compare($self, "<=", dat)==FLGR_TRUE);
  }
  int __eq__(FLGR_Data2D *dat) {
    return (flgr2d_compare($self, "==", dat)==FLGR_TRUE);
  }
  int __ne__(FLGR_Data2D *dat) {
    return (flgr2d_compare($self, "!=", dat)==FLGR_TRUE);
  }
  int __gt__(FLGR_Data2D *dat) {
    return (flgr2d_compare($self, ">", dat)==FLGR_TRUE);
  }
  int __ge__(FLGR_Data2D *dat) {
    return (flgr2d_compare($self, ">=", dat)==FLGR_TRUE);
  }

  int __lt__(FLGR_Vector *vec) {
    return (flgr2d_compare_const_ptr($self, "<", vec)==FLGR_TRUE);
  }
  int __le__(FLGR_Vector *vec) {
    return (flgr2d_compare_const_ptr($self, "<=", vec)==FLGR_TRUE);
  }
  int __eq__(FLGR_Vector *vec) {
    return (flgr2d_compare_const_ptr($self, "==", vec)==FLGR_TRUE);
  }
  int __ne__(FLGR_Vector *vec) {
    return (flgr2d_compare_const_ptr($self, "!=", vec)==FLGR_TRUE);
  }
  int __gt__(FLGR_Vector *vec) {
    return (flgr2d_compare_const_ptr($self, ">", vec)==FLGR_TRUE);
  }
  int __ge__(FLGR_Vector *vec) {
    return (flgr2d_compare_const_ptr($self, ">=", vec)==FLGR_TRUE);
  }

  int __lt__(SwigObject val) {
    FLGR_Vector *vec = flgr_vector_create($self->spp, $self->type);
    int test = 0;

    if(SwigCheckIntType(val)) {
      switch($self->type) {
      case FLGR_UINT8:
	flgr_vector_populate_from_scalar_fgUINT8(vec,(fgUINT8) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT16:
	flgr_vector_populate_from_scalar_fgUINT16(vec,(fgUINT16) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT32:
	flgr_vector_populate_from_scalar_fgUINT32(vec,(fgUINT32) (CUInt_FromSwigInt(val)));break;
      case FLGR_INT8:
	flgr_vector_populate_from_scalar_fgINT8(vec,(fgINT8) (CInt_FromSwigInt(val)));break;
      case FLGR_INT16:
	flgr_vector_populate_from_scalar_fgINT16(vec,(fgINT16) (CInt_FromSwigInt(val)));break;
      case FLGR_INT32:
	flgr_vector_populate_from_scalar_fgINT32(vec,(fgINT32) (CInt_FromSwigInt(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
      
    }else if(SwigCheckDblType(val)) {
      switch($self->type) {
      case FLGR_FLOAT32:
	flgr_vector_populate_from_scalar_fgFLOAT32(vec,(fgFLOAT32) (CDouble_FromSwigFloat(val)));break;
      case FLGR_FLOAT64:
	flgr_vector_populate_from_scalar_fgFLOAT64(vec,(fgFLOAT64) (CDouble_FromSwigFloat(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
       
    }else if(SwigCheckArrayType(val)) {
      if(SwigArraySize(val) >= $self->spp) {
	int size = $self->spp;
	int i;

	if(vec->type==FLGR_UINT8) {
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT8(vec,i,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_UINT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT16(vec,i,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_UINT32) {	
  	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT32(vec,i,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_INT8) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT8(vec,i,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_INT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT16(vec,i,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_INT32) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT32(vec,i,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_FLOAT32) {		
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT32(vec,i,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));
   
	}else if(vec->type==FLGR_FLOAT64) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT64(vec,i,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_BIT) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgBIT(vec,i,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
   
	}else {					
	  flgr_vector_destroy(vec);
	  POST_ERROR("unknown type\n");
	  return 0;
	}	
      }else {
	flgr_vector_destroy(vec);
	POST_ERROR("list or array specified too short\n");
	return 0;
      }
    }

    test = (flgr2d_compare_const_ptr($self,"<",vec)==FLGR_TRUE);

    flgr_vector_destroy(vec);
    return test;
  }




  int __le__(SwigObject val) {
    FLGR_Vector *vec = flgr_vector_create($self->spp, $self->type);
    int test = 0;

    if(SwigCheckIntType(val)) {
      switch($self->type) {
      case FLGR_UINT8:
	flgr_vector_populate_from_scalar_fgUINT8(vec,(fgUINT8) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT16:
	flgr_vector_populate_from_scalar_fgUINT16(vec,(fgUINT16) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT32:
	flgr_vector_populate_from_scalar_fgUINT32(vec,(fgUINT32) (CUInt_FromSwigInt(val)));break;
      case FLGR_INT8:
	flgr_vector_populate_from_scalar_fgINT8(vec,(fgINT8) (CInt_FromSwigInt(val)));break;
      case FLGR_INT16:
	flgr_vector_populate_from_scalar_fgINT16(vec,(fgINT16) (CInt_FromSwigInt(val)));break;
      case FLGR_INT32:
	flgr_vector_populate_from_scalar_fgINT32(vec,(fgINT32) (CInt_FromSwigInt(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
      
    }else if(SwigCheckDblType(val)) {
      switch($self->type) {
      case FLGR_FLOAT32:
	flgr_vector_populate_from_scalar_fgFLOAT32(vec,(fgFLOAT32) (CDouble_FromSwigFloat(val)));break;
      case FLGR_FLOAT64:
	flgr_vector_populate_from_scalar_fgFLOAT64(vec,(fgFLOAT64) (CDouble_FromSwigFloat(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
       
    }else if(SwigCheckArrayType(val)) {
      if(SwigArraySize(val) >= $self->spp) {
	int size = $self->spp;
	int i;

	if(vec->type==FLGR_UINT8) {
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT8(vec,i,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_UINT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT16(vec,i,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_UINT32) {	
  	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT32(vec,i,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_INT8) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT8(vec,i,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_INT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT16(vec,i,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_INT32) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT32(vec,i,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_FLOAT32) {		
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT32(vec,i,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));
   
	}else if(vec->type==FLGR_FLOAT64) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT64(vec,i,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_BIT) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgBIT(vec,i,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
   
	}else {					
	  flgr_vector_destroy(vec);
	  POST_ERROR("unknown type\n");
	  return 0;
	}	
      }else {
	flgr_vector_destroy(vec);
	POST_ERROR("list or array specified too short\n");
	return 0;
      }
    }

    test = (flgr2d_compare_const_ptr($self,"<=",vec)==FLGR_TRUE);

    flgr_vector_destroy(vec);
    return test;
  }



  int __eq__(SwigObject val) {
    FLGR_Vector *vec = flgr_vector_create($self->spp, $self->type);
    int test = 0;

    if(SwigCheckIntType(val)) {
      switch($self->type) {
      case FLGR_UINT8:
	flgr_vector_populate_from_scalar_fgUINT8(vec,(fgUINT8) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT16:
	flgr_vector_populate_from_scalar_fgUINT16(vec,(fgUINT16) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT32:
	flgr_vector_populate_from_scalar_fgUINT32(vec,(fgUINT32) (CUInt_FromSwigInt(val)));break;
      case FLGR_INT8:
	flgr_vector_populate_from_scalar_fgINT8(vec,(fgINT8) (CInt_FromSwigInt(val)));break;
      case FLGR_INT16:
	flgr_vector_populate_from_scalar_fgINT16(vec,(fgINT16) (CInt_FromSwigInt(val)));break;
      case FLGR_INT32:
	flgr_vector_populate_from_scalar_fgINT32(vec,(fgINT32) (CInt_FromSwigInt(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
      
    }else if(SwigCheckDblType(val)) {
      switch($self->type) {
      case FLGR_FLOAT32:
	flgr_vector_populate_from_scalar_fgFLOAT32(vec,(fgFLOAT32) (CDouble_FromSwigFloat(val)));break;
      case FLGR_FLOAT64:
	flgr_vector_populate_from_scalar_fgFLOAT64(vec,(fgFLOAT64) (CDouble_FromSwigFloat(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
       
    }else if(SwigCheckArrayType(val)) {
      if(SwigArraySize(val) >= $self->spp) {
	int size = $self->spp;
	int i;

	if(vec->type==FLGR_UINT8) {
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT8(vec,i,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_UINT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT16(vec,i,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_UINT32) {	
  	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT32(vec,i,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_INT8) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT8(vec,i,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_INT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT16(vec,i,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_INT32) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT32(vec,i,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_FLOAT32) {		
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT32(vec,i,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));
   
	}else if(vec->type==FLGR_FLOAT64) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT64(vec,i,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_BIT) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgBIT(vec,i,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
   
	}else {					
	  flgr_vector_destroy(vec);
	  POST_ERROR("unknown type\n");
	  return 0;
	}	
      }else {
	flgr_vector_destroy(vec);
	POST_ERROR("list or array specified too short\n");
	return 0;
      }
    }

    test = (flgr2d_compare_const_ptr($self,"==",vec)==FLGR_TRUE);

    flgr_vector_destroy(vec);
    return test;
  }



  int __ne__(SwigObject val) {
    FLGR_Vector *vec = flgr_vector_create($self->spp, $self->type);
    int test = 0;

    if(SwigCheckIntType(val)) {
      switch($self->type) {
      case FLGR_UINT8:
	flgr_vector_populate_from_scalar_fgUINT8(vec,(fgUINT8) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT16:
	flgr_vector_populate_from_scalar_fgUINT16(vec,(fgUINT16) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT32:
	flgr_vector_populate_from_scalar_fgUINT32(vec,(fgUINT32) (CUInt_FromSwigInt(val)));break;
      case FLGR_INT8:
	flgr_vector_populate_from_scalar_fgINT8(vec,(fgINT8) (CInt_FromSwigInt(val)));break;
      case FLGR_INT16:
	flgr_vector_populate_from_scalar_fgINT16(vec,(fgINT16) (CInt_FromSwigInt(val)));break;
      case FLGR_INT32:
	flgr_vector_populate_from_scalar_fgINT32(vec,(fgINT32) (CInt_FromSwigInt(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
      
    }else if(SwigCheckDblType(val)) {
      switch($self->type) {
      case FLGR_FLOAT32:
	flgr_vector_populate_from_scalar_fgFLOAT32(vec,(fgFLOAT32) (CDouble_FromSwigFloat(val)));break;
      case FLGR_FLOAT64:
	flgr_vector_populate_from_scalar_fgFLOAT64(vec,(fgFLOAT64) (CDouble_FromSwigFloat(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
       
    }else if(SwigCheckArrayType(val)) {
      if(SwigArraySize(val) >= $self->spp) {
	int size = $self->spp;
	int i;

	if(vec->type==FLGR_UINT8) {
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT8(vec,i,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_UINT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT16(vec,i,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_UINT32) {	
  	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT32(vec,i,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_INT8) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT8(vec,i,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_INT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT16(vec,i,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_INT32) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT32(vec,i,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_FLOAT32) {		
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT32(vec,i,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));
   
	}else if(vec->type==FLGR_FLOAT64) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT64(vec,i,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_BIT) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgBIT(vec,i,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
   
	}else {					
	  flgr_vector_destroy(vec);
	  POST_ERROR("unknown type\n");
	  return 0;
	}	
      }else {
	flgr_vector_destroy(vec);
	POST_ERROR("list or array specified too short\n");
	return 0;
      }
    }

    test = (flgr2d_compare_const_ptr($self,"!=",vec)==FLGR_TRUE);

    flgr_vector_destroy(vec);
    return test;
  }




  int __gt__(SwigObject val) {
    FLGR_Vector *vec = flgr_vector_create($self->spp, $self->type);
    int test = 0;

    if(SwigCheckIntType(val)) {
      switch($self->type) {
      case FLGR_UINT8:
	flgr_vector_populate_from_scalar_fgUINT8(vec,(fgUINT8) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT16:
	flgr_vector_populate_from_scalar_fgUINT16(vec,(fgUINT16) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT32:
	flgr_vector_populate_from_scalar_fgUINT32(vec,(fgUINT32) (CUInt_FromSwigInt(val)));break;
      case FLGR_INT8:
	flgr_vector_populate_from_scalar_fgINT8(vec,(fgINT8) (CInt_FromSwigInt(val)));break;
      case FLGR_INT16:
	flgr_vector_populate_from_scalar_fgINT16(vec,(fgINT16) (CInt_FromSwigInt(val)));break;
      case FLGR_INT32:
	flgr_vector_populate_from_scalar_fgINT32(vec,(fgINT32) (CInt_FromSwigInt(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
      
    }else if(SwigCheckDblType(val)) {
      switch($self->type) {
      case FLGR_FLOAT32:
	flgr_vector_populate_from_scalar_fgFLOAT32(vec,(fgFLOAT32) (CDouble_FromSwigFloat(val)));break;
      case FLGR_FLOAT64:
	flgr_vector_populate_from_scalar_fgFLOAT64(vec,(fgFLOAT64) (CDouble_FromSwigFloat(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
       
    }else if(SwigCheckArrayType(val)) {
      if(SwigArraySize(val) >= $self->spp) {
	int size = $self->spp;
	int i;

	if(vec->type==FLGR_UINT8) {
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT8(vec,i,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_UINT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT16(vec,i,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_UINT32) {	
  	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT32(vec,i,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_INT8) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT8(vec,i,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_INT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT16(vec,i,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_INT32) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT32(vec,i,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_FLOAT32) {		
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT32(vec,i,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));
   
	}else if(vec->type==FLGR_FLOAT64) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT64(vec,i,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_BIT) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgBIT(vec,i,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
   
	}else {					
	  flgr_vector_destroy(vec);
	  POST_ERROR("unknown type\n");
	  return 0;
	}	
      }else {
	flgr_vector_destroy(vec);
	POST_ERROR("list or array specified too short\n");
	return 0;
      }
    }

    test = (flgr2d_compare_const_ptr($self,">",vec)==FLGR_TRUE);

    flgr_vector_destroy(vec);
    return test;
  }


  int __ge__(SwigObject val) {
    FLGR_Vector *vec = flgr_vector_create($self->spp, $self->type);
    int test = 0;

    if(SwigCheckIntType(val)) {
      switch($self->type) {
      case FLGR_UINT8:
	flgr_vector_populate_from_scalar_fgUINT8(vec,(fgUINT8) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT16:
	flgr_vector_populate_from_scalar_fgUINT16(vec,(fgUINT16) (CUInt_FromSwigInt(val)));break;
      case FLGR_UINT32:
	flgr_vector_populate_from_scalar_fgUINT32(vec,(fgUINT32) (CUInt_FromSwigInt(val)));break;
      case FLGR_INT8:
	flgr_vector_populate_from_scalar_fgINT8(vec,(fgINT8) (CInt_FromSwigInt(val)));break;
      case FLGR_INT16:
	flgr_vector_populate_from_scalar_fgINT16(vec,(fgINT16) (CInt_FromSwigInt(val)));break;
      case FLGR_INT32:
	flgr_vector_populate_from_scalar_fgINT32(vec,(fgINT32) (CInt_FromSwigInt(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
      
    }else if(SwigCheckDblType(val)) {
      switch($self->type) {
      case FLGR_FLOAT32:
	flgr_vector_populate_from_scalar_fgFLOAT32(vec,(fgFLOAT32) (CDouble_FromSwigFloat(val)));break;
      case FLGR_FLOAT64:
	flgr_vector_populate_from_scalar_fgFLOAT64(vec,(fgFLOAT64) (CDouble_FromSwigFloat(val)));break;
      default:
	flgr_vector_destroy(vec);
	return 0;
      }
       
    }else if(SwigCheckArrayType(val)) {
      if(SwigArraySize(val) >= $self->spp) {
	int size = $self->spp;
	int i;

	if(vec->type==FLGR_UINT8) {
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT8(vec,i,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_UINT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT16(vec,i,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_UINT32) {	
  	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgUINT32(vec,i,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_INT8) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT8(vec,i,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_INT16) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT16(vec,i,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
    
	}else if(vec->type==FLGR_INT32) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgINT32(vec,i,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(val,i))));
  
	}else if(vec->type==FLGR_FLOAT32) {		
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT32(vec,i,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));
   
	}else if(vec->type==FLGR_FLOAT64) {	
	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgFLOAT64(vec,i,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(val,i))));

	}else if(vec->type==FLGR_BIT) {	
 	  for(i=0 ; i<size ; i++) 
	    flgr_vector_set_element_fgBIT(vec,i,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(val,i))));
   
	}else {					
	  flgr_vector_destroy(vec);
	  POST_ERROR("unknown type\n");
	  return 0;
	}	
      }else {
	flgr_vector_destroy(vec);
	POST_ERROR("list or array specified too short\n");
	return 0;
      }
    }

    test = (flgr2d_compare_const_ptr($self,">=",vec)==FLGR_TRUE);

    flgr_vector_destroy(vec);
    return test;
  }



 
  FLGR_Data1D *__getitem__(int i) {
    if(i<0) return  NULL;
    if(i>=$self->size_y+16) return NULL;
    return $self->row[i];
  }

  void from_string(SwigObject obj) {
    char *str = CString_FromSwigString(obj);
    flgr2d_import_raw_ptr($self, (void *) str);
  }

  SwigObject to_string() {
    SwigObject obj;
    void *str = malloc($self->spp * $self->size_x * $self->size_y * flgr_get_sizeof($self->type));
    flgr2d_export_raw_ptr(str,$self);
    obj = SwigString_FromCString(str);
    free(str);
    return obj;
  }


  SwigObject to_raw() {
    void *tab = $self->array;
    int lenX = $self->size_x*$self->spp;
    int i,j;
    int k=0;
    SwigObject obj = SwigObjectEmpty;    

    obj = SwigCreateArray($self->size_y*lenX);

    if($self->type==FLGR_UINT8) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCUInt((unsigned int) flgr2d_get_data_array_fgUINT8(tab,i,j)) );
      
    }else if($self->type==FLGR_UINT16) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCUInt((unsigned int) flgr2d_get_data_array_fgUINT16(tab,i,j)) );
      
    }else if($self->type==FLGR_UINT32) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCUInt((unsigned int) flgr2d_get_data_array_fgUINT32(tab,i,j)) );
     
    }else if($self->type==FLGR_INT8) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCUInt((int) flgr2d_get_data_array_fgINT8(tab,i,j)) );
     
    }else if($self->type==FLGR_INT16) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCInt((int) flgr2d_get_data_array_fgINT16(tab,i,j)) );
    
    }else if($self->type==FLGR_INT32) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCInt((int) flgr2d_get_data_array_fgINT32(tab,i,j)) );
      
    }else if($self->type==FLGR_FLOAT32) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigFloat_FromCDouble((double) flgr2d_get_data_array_fgFLOAT32(tab,i,j)) );
        
    }else if($self->type==FLGR_FLOAT64) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigFloat_FromCDouble((double) flgr2d_get_data_array_fgFLOAT64(tab,i,j)) );
     
    }else if($self->type==FLGR_BIT) {
      for(i=0 ; i<$self->size_y ; i++) 
	for(j=0 ; j<lenX ; j++) 
	  SwigSetArrayVal( obj, k++, SwigInt_FromCUInt((unsigned int) flgr2d_get_data_array_fgBIT(tab,i,j)) );

    }else {
      POST_ERROR("type unknown\n");
      return SwigObjectEmpty;
    }
    
    return obj;
  }

  void from_raw( SwigObject raw_row) {
    void *tab = $self->array;
    int lenX = $self->size_x*$self->spp;
    int size = $self->size_y;
    int i,j,k=0;

    if($self->type==FLGR_UINT8) {
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgUINT8(tab,i,j,(fgUINT8) (CUInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));

    }else if($self->type==FLGR_UINT16) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgUINT16(tab,i,j,(fgUINT16) (CUInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));
    
    }else if($self->type==FLGR_UINT32) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgUINT32(tab,i,j,(fgUINT32) (CUInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));
   
    }else if($self->type==FLGR_INT8) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgINT8(tab,i,j,(fgINT8) (CInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));
    
    }else if($self->type==FLGR_INT16) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgINT16(tab,i,j,(fgINT16) (CInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));
   
    }else if($self->type==FLGR_INT32) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgINT32(tab,i,j,(fgINT32) (CInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));
  
    }else if($self->type==FLGR_FLOAT32) {		
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgFLOAT32(tab,i,j,(fgFLOAT32) (CDouble_FromSwigFloat(SwigGetArrayVal(raw_row,k++))));
   
    }else if($self->type==FLGR_FLOAT64) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgFLOAT64(tab,i,j,(fgFLOAT64) (CDouble_FromSwigFloat(SwigGetArrayVal(raw_row,k++))));

    }else if($self->type==FLGR_BIT) {	
      for(i=0 ; i<size ; i++)
	for(j=0 ; j<lenX ; j++) 
	  flgr2d_set_data_array_fgBIT(tab,i,j,(fgBIT) (CUInt_FromSwigInt(SwigGetArrayVal(raw_row,k++))));
  
    }else {					
      POST_ERROR("unknown type\n");
    }

  }



};




%feature("autodoc","""
[in] Height
[in] Width
[in] Sample Per Pixel
[in] data type used in image
[in] shape
[in] connexity
[return] FLGR_Data2D\n
Create a neighborhood.\n
Type could be:
   => FLGR_BIT
   => FLGR_UINT8
   => FLGR_UINT16
   => FLGR_UINT32
   => FLGR_INT8
   => FLGR_INT16
   => FLGR_INT32
   => FLGR_FLOAT32
   => FLGR_FLOAT64\n
Shape could be: 
   => FLGR_RECT
   => FLGR_HEX (only for 6-connexity)
   => FLGR_CROSS1 ( + )
   => FLGR_CROSS2 ( X )
   => FLGR_DISC
   => FLGR_ELLIPSE
   => FLGR_BSLASH ( \ )
   => FLGR_SLASH  ( / )
   => FLGR_DIAMOND
   => FLGR_OCTAGON
   => FLGR_USER_SHAPE\n
Connexity could be:
   => FLGR_8_CONNEX
   => FLGR_6_CONNEX
   => FLGR_4_CONNEX\n
No verifications are done. For example,  you can use a RECT shape in 6-connexity, so take care !
Values are not initialized regarding the shape
""") flgr2d_create;
FLGR_Data2D *flgr2d_create(int size_y, int size_x, int spp, FLGR_Type type, FLGR_Shape shape, FLGR_Connexity connexity);

%feature("autodoc","""
[in] FLGR_Data2D source
[return] FLGR_Data2D\n
Create a 2d data using the FLGR_Data2D Width, Height, Spp, Type, Name.
Source values are not copied to the destination array
""") flgr2d_create_from;
FLGR_Data2D *flgr2d_create_from(FLGR_Data2D *datsrc);

%feature("autodoc","""
[in] FLGR_Data2D source
[in] Number of subparts to consider
[in] subpart index to link with
[in] overlap size between parts
[return] FLGR_Data2D\n
Create a 2d data where each row are linked to another data2D.
""") flgr2d_create_pixmap_linkflgr2d_create_pixmap_link;
FLGR_Data2D *flgr2d_create_pixmap_link(FLGR_Data2D *datain, int partsNumber, int partIndex, int overlapSize);

%feature("autodoc","""
[in] Height
[in] Width
[in] Sample Per Pixel
[in] data type used in image
[in] shape
[in] connexity
[return] FLGR_Data2D\n
Create a neighborhood.\n
Type could be:
   => FLGR_BIT
   => FLGR_UINT8
   => FLGR_UINT16
   => FLGR_UINT32
   => FLGR_INT8
   => FLGR_INT16
   => FLGR_INT32
   => FLGR_FLOAT32
   => FLGR_FLOAT64\n
Shape could be: 
   => FLGR_RECT
   => FLGR_HEX (only for 6-connexity)
   => FLGR_CROSS1 ( + )
   => FLGR_CROSS2 ( X )
   => FLGR_DISC
   => FLGR_ELLIPSE
   => FLGR_BSLASH ( \ )
   => FLGR_SLASH  ( / )
   => FLGR_DIAMOND
   => FLGR_OCTAGON
   => FLGR_USER_SHAPE\n
Connexity could be:
   => FLGR_8_CONNEX
   => FLGR_6_CONNEX
   => FLGR_4_CONNEX\n
No verifications are done. For example,  you can use a RECT shape in 6-connexity, so take care !
""") flgr2d_create_neighborhood;
FLGR_Data2D *flgr2d_create_neighborhood(int size_y, int size_x, int spp, FLGR_Type type, 
					FLGR_Shape shape, FLGR_Connexity connexity);

%feature("autodoc","""
[in] FLGR_Data2D source
[return] FLGR_Data2D\n
Create a neighborhood using the FLGR_Data2D Width, Height, Spp, Type, Name.
The neighborhood array is generated only using the Shape name of the FLGR_Data2D input.
Array is filled with values thanks to shape information retrieve in the FLGR_Data2D Source.
Source values are not copied to the destination array
""") flgr2d_create_neighborhood_from;
FLGR_Data2D *flgr2d_create_neighborhood_from(FLGR_Data2D *nhbsrc);

%feature("autodoc","""
[in] Sample Per Pixel
[in] type
[in] connexity
[return] FLGR_Data2D\n
Connexity could be:
   => FLGR_8_CONNEX
   => FLGR_6_CONNEX
   => FLGR_4_CONNEX\n
Allocate a FLGR_Data2D structure only with connexity information.
The size is the smallest for the connexity specified
""") flgr2d_create_neighborhood_from_connexity;
FLGR_Data2D *flgr2d_create_neighborhood_from_connexity( int spp, FLGR_Type type, FLGR_Connexity connexity);


%feature("autodoc","""
[in] Height
[in] Width
[in] Sample Per Pixel
[in] type
[return] FLGR_Data2D\n
Create a pixmap. Not array initialization is performed.\n
Type could be:
   => FLGR_BIT
   => FLGR_UINT8
   => FLGR_UINT16
   => FLGR_UINT32
   => FLGR_INT8
   => FLGR_INT16
   => FLGR_INT32
   => FLGR_FLOAT32
   => FLGR_FLOAT64\n
""") flgr2d_create_pixmap;
FLGR_Data2D *flgr2d_create_pixmap(int size_y, int size_x, int spp, FLGR_Type type);

%feature("autodoc","""
[in] FLGR_Data2D source
[return] FLGR_Data2D\n
Create a pixmap using the FLGR_Data2D input given.\n
Pixmap array is just created but not copied from the input
""") flgr2d_create_pixmap_from;
FLGR_Data2D *flgr2d_create_pixmap_from(FLGR_Data2D *imgsrc);


%feature("autodoc","""
[inout] FLGR_Data2D source
[return] FLGR_RET_OK\n
Set all pixels to zero
""") flgr2d_clear_all;
FLGR_Ret flgr2d_clear_all(FLGR_Data2D *data);


%feature("autodoc","""
[in] FLGR_Data2D source1
[in] FLGR_Data2D source2
[in] String
[return] FLGR_Ret\n
Test if data have same size, same type, valid type and same Sample per pixel.
""") flgr2d_is_data_same_attributes;
FLGR_Ret flgr2d_is_data_same_attributes(FLGR_Data2D *dat1, FLGR_Data2D *dat2, 
					const char *callingFunction);

%feature("autodoc","""
[in] FLGR_Data2D source 1
[in] FLGR_Data2D source 2
[return] FLGR_Ret\n
Test if data have same same type and valid type.
""") flgr2d_is_data_same_type;
FLGR_Ret flgr2d_is_data_same_type(FLGR_Data2D *dat1, FLGR_Data2D *dat2);

%feature("autodoc","""
[in] FLGR_Data2D source 1
[in] FLGR_Data2D source 2
[return] FLGR_Ret\n
Test if data have same size.
""") flgr2d_is_data_same_size;
FLGR_Ret flgr2d_is_data_same_size(FLGR_Data2D *dat1, FLGR_Data2D *dat2);

%feature("autodoc","""
[in] FLGR_Data2D source 1
[in] FLGR_Data2D source 2
[return] FLGR_Ret\n
Test if data have same sample per pixel.
""") flgr2d_is_data_same_spp;
FLGR_Ret flgr2d_is_data_same_spp(FLGR_Data2D *dat1, FLGR_Data2D *dat2);

%feature("autodoc","""
[in] FLGR_Data2D
[in] Shape
[return] FLGR_Ret\n
Change the shape\n
Shape could be: 
   => FLGR_RECT
   => FLGR_HEX (only for 6-connexity)
   => FLGR_CROSS1 ( + )
   => FLGR_CROSS2 ( X )
   => FLGR_DISC
   => FLGR_ELLIPSE
   => FLGR_BSLASH ( \ )
   => FLGR_SLASH  ( / )
   => FLGR_DIAMOND
   => FLGR_OCTAGON
   => FLGR_USER_SHAPE\n
""") flgr2d_data_set_shape;
void flgr2d_data_set_shape(FLGR_Data2D *dat, FLGR_Shape shape);

%feature("autodoc","""
[in] FLGR_Data2D
[in] Connexity
[return] FLGR_Ret\n
Change the connexity\n
Connexity could be:
   => FLGR_8_CONNEX
   => FLGR_6_CONNEX
   => FLGR_4_CONNEX\n
""") flgr2d_data_set_connexity;
void flgr2d_data_set_connexity(FLGR_Data2D *dat, FLGR_Connexity connexity);






 









